package com.swagger.demo.threadTest;

import com.swagger.demo.threads.MyCallable;
import com.swagger.demo.threads.MyRunnable;
import com.swagger.demo.threads.Mythread;

import java.util.concurrent.*;

/**
 * @auther heyang
 * @date 2020/9/16 21:30
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //继承Thread方式 创建多线程
       /* Mythread mythread = new Mythread();
        mythread.start();*/

        //实现Runnable方式实现多线程 线程不安全
       /* MyRunnable myRunnable = new MyRunnable();
        Thread t1 = new Thread(myRunnable, "黄牛1");
        Thread t2 = new Thread(myRunnable, "黄牛2");
        Thread t3 = new Thread(myRunnable, "黄牛3");
        t1.start();
        t2.start();
        t3.start();*/
//        //实现callable接口 方式实现多线程
//        MyCallable myCallable = new MyCallable();
//        ExecutorService executorService = Executors.newFixedThreadPool(3);
//        Future<Integer> t1 = executorService.submit(myCallable);
//        Future<Integer> t2 = executorService.submit(myCallable);
//        Future<Integer> t3 = executorService.submit(myCallable);
//        try {
//            System.out.println(t1.get());
//            System.out.println(t2.get());
//            System.out.println(t3.get());
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        }
        //实现Runnable方式实现多线程 线程不安全
        MyRunnable myRunnable = new MyRunnable();
        new Thread(myRunnable, "黄牛1").start();
        new Thread(myRunnable, "黄牛2").start();
        new Thread(myRunnable, "黄牛3").start();


    }

    private static void prints() {
        for (int i = 0; i < 2000; i++) {
            System.out.println("主线程调用方法" + i);
        }
    }

}
